package com.x.common.security.config;

import com.x.common.security.interceptor.XServerProtectInterceptor;
import com.x.common.security.properties.XCloudSecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 蔡朋宏
 */
public class XCloudSecurityInterceptorConfig implements WebMvcConfigurer {

  private XCloudSecurityProperties xCloudSecurityProperties;

  @Autowired
  public void setProperties(XCloudSecurityProperties properties) {
    this.xCloudSecurityProperties = properties;
  }

  @Bean
  public HandlerInterceptor xServerProtectInterceptor() {
    XServerProtectInterceptor interceptor = new XServerProtectInterceptor();
    interceptor.setProperties(xCloudSecurityProperties);
    return interceptor;
  }

  @Override
  @SuppressWarnings("all")
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(xServerProtectInterceptor());
  }
}
